package com.rory.service.serviceInterfaceImpl;

import com.rory.dao.expand.UserDao;
import com.rory.dao.generate.UserMapper;
import com.rory.entity.generate.User;
import com.rory.exception.BaseObjException;
import com.rory.exception.UserNotLoginException;
import com.rory.service.CrudService;
import com.rory.service.serviceInterface.LoginService;
import com.rory.util.EncodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * class: LoginService.
 * Created by Rory on 2016/11/22.
 * use:  .
 * other:  .
 */
@Service
public class LoginServiceImpl extends CrudService<UserMapper, User> implements LoginService {

    @Autowired
    private UserDao userDao;

    @Override
    public User userLogin(String userName, String userPAssword) throws Exception {
        User user = null;
        try {
            user = userDao.getUserByUserNameAndUserPassword(userName, EncodeUtil.shaEncode(userPAssword));
        }catch (Exception e){
            throw e;
        }finally {
            if(user == null){
                throw new UserNotLoginException("asd");
            }
        }
        return user ;
    }
}
